#ifndef YCCOREPRESENTER_H
#define YCCOREPRESENTER_H

#include "modeltype.h"
#include <QJsonObject>

namespace yc {

struct Presenter
{
    int id;
    QString platform_id;
    QString platform_sec_uid;
    int platform;
    QString nickname;
    QString avatar;
    int category;
    int status;
    int active_live;
    int audience_count;
    QDateTime update_time;
    int updater;

    Presenter()
        : id(0),
          platform(PlatformType::UNKNOWN_PLATFORM_TYPE),
          category(0),
          status(LiveStatus::INACTIVE_LIVE_STATUS),
          active_live(0),
          audience_count(0),
          update_time(QDateTime::currentDateTime()),
          updater(0)
    {
    }
    explicit Presenter(const QJsonObject& jo) { this->operator=(jo); }
    Presenter(int platform_, const QJsonObject& jo) : Presenter(jo) { platform = platform_; }

    Presenter& operator=(const QJsonObject& jo)
    {
        id = jo["id"].toInt();
        platform_id = jo["platformId"].toString();
        platform_sec_uid = jo["platformSecUid"].toString();
        platform = jo["platform"].toInt(PlatformType::UNKNOWN_PLATFORM_TYPE);
        nickname = jo["nickname"].toString();
        avatar = jo["avatar"].toString();
        category = jo["category"].toInt();
        status = jo["status"].toInt(LiveStatus::INACTIVE_LIVE_STATUS);
        active_live = jo["activeLive"].toInt();
        audience_count = jo["audienceCount"].toInt();
        update_time = QDateTime::fromString(jo["updateTime"].toString(), Qt::ISODate);
        if (!update_time.isValid()) {
            update_time = QDateTime::currentDateTime();
        }
        updater = jo["updater"].toInt();
        return *this;
    }

    QJsonObject toJsonObject() const
    {
        return QJsonObject { { "id", id },
                             { "platformId", platform_id },
                             { "platformSecUid", platform_sec_uid },
                             { "platform", platform },
                             { "nickname", nickname },
                             { "avatar", avatar },
                             { "category", category },
                             { "status", status },
                             { "activeLive", active_live },
                             { "audienceCount", audience_count },
                             { "updateTime", update_time.toString(Qt::ISODate) },
                             { "updater", updater } };
    }
};

} // namespace yc

#endif // YCCOREPRESENTER_H
